﻿using Acme.BookStore.Storage.DTO;
using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.BookStore.Storage
{
    public class ApprovalHistoryAppService : ApplicationService, IApprovalHistoryAppService
    {
        private readonly IRepository<ApprovalHistory, Guid> _historyRepository;

        public ApprovalHistoryAppService(IRepository<ApprovalHistory, Guid> historyRepository)
        {
            _historyRepository = historyRepository;
        }

        public async Task<List<ApprovalHistoryDto>> GetListByInboundIdAsync(Guid inboundId)
        {
            var history = await _historyRepository.GetListAsync(x => x.InboundManageId == inboundId);
            return ObjectMapper.Map<List<ApprovalHistory>, List<ApprovalHistoryDto>>(history.OrderBy(h => h.CreationTime).ToList());
        }
    }
}
